﻿using System;
using System.Data;
using System.Xml;

namespace XMLHandle
{
    class Program
    {
        static void Main(string[] args)
        {

            string savePath = @"C:\Users\wulix\Desktop\BRCM\100.xml";
            CsvHelper csvHelper = new CsvHelper();
            DataTable dt = new DataTable();
            DataColumn dc1 = new DataColumn("标准号", Type.GetType("System.String"));
            DataColumn dc2 = new DataColumn("描述", Type.GetType("System.String"));
            dt.Columns.Add(dc1);
            dt.Columns.Add(dc2);
            dt = csvHelper.csv2dt(@"C:\Users\wulix\Desktop\BRCM\1065.csv", 0, dt);


            XmlDocument objXmlDoc = new XmlDocument();
            objXmlDoc = XmlHelper.LoadXml(savePath);
            XmlElement rootElement = objXmlDoc.CreateElement("wulix");
            objXmlDoc.AppendChild(rootElement);//主节点
            for (int i = 0; i < dt.Rows.Count; i++)
            {
                XmlNode objNode = objXmlDoc.SelectSingleNode("wulix");

                // XmlElement xmlElement1 = objXmlDoc.CreateElement("CatalogItem");
                // xmlElement1.SetAttribute("name", dt.Rows[i][0].ToString()+"仪表");
                // xmlElement1.SetAttribute("type", "Catalog_HPR1000_Ins");
                // XmlElement xmlElementDefaults = objXmlDoc.CreateElement("Defaults");

                // XmlElement xmlElementProperty1 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty1.SetAttribute("definition", "HPR1000_Property_Design");
                // xmlElementProperty1.SetAttribute("name", "HPR1000_Property_Design/@Drawing_Label");
                // xmlElementProperty1.SetAttribute("isHidden", "true");
                // xmlElementProperty1.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty2 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty2.SetAttribute("definition", "HPR1000_Property_Design");
                // xmlElementProperty2.SetAttribute("name", "HPR1000_Property_Design/@Conversion_Number");
                // xmlElementProperty2.SetAttribute("isHidden", "true");
                // //xmlElementProperty2.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty3 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty3.SetAttribute("definition", "HPR1000_Property_Design");
                // xmlElementProperty3.SetAttribute("name", "HPR1000_Property_Design/@Conversion_Name");
                // xmlElementProperty3.SetAttribute("isHidden", "true");
                // //xmlElementProperty3.SetAttribute("isEditable", "false");


                // XmlElement xmlElementProperty4 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty4.SetAttribute("definition", "HPR1000_Property_Manufacturing");
                // xmlElementProperty4.SetAttribute("name", "ACP1000_Property_Manufacturing/@Material_Parameter");
                // xmlElementProperty4.SetAttribute("isHidden", "true");
                // xmlElementProperty4.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty5 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty5.SetAttribute("definition", "HPR1000_Property_Manufacturing");
                // xmlElementProperty5.SetAttribute("name", "ACP1000_Property_Manufacturing/@Load_Information");
                // xmlElementProperty5.SetAttribute("isHidden", "true");
                //// xmlElementProperty5.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty6 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty6.SetAttribute("definition", "HPR1000_Property_Manufacturing");
                // xmlElementProperty6.SetAttribute("name", "ACP1000_Property_Manufacturing/@Number");
                // xmlElementProperty6.SetAttribute("isHidden", "true");
                // //xmlElementProperty6.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty7 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty7.SetAttribute("definition", "HPR1000_Property_Design");
                // xmlElementProperty7.SetAttribute("name", "HPR1000_Property_Design/@System");
                // xmlElementProperty7.SetAttribute("value", dt.Rows[i][0].ToString());
                // //xmlElementProperty7.SetAttribute("isEditable", "false");

                // XmlElement xmlElementProperty8 = objXmlDoc.CreateElement("Property");
                // xmlElementProperty8.SetAttribute("definition", "ObjectMaterial");
                // xmlElementProperty8.SetAttribute("name", "ObjectMaterial/@PartDefinition");
                // xmlElementProperty8.SetAttribute("value", "Instrument::" + dt.Rows[i][0].ToString() + "仪表");
                // objNode.AppendChild(xmlElement1);
                // xmlElement1.AppendChild(xmlElementDefaults);
                // xmlElementDefaults.AppendChild(xmlElementProperty1);
                // xmlElementDefaults.AppendChild(xmlElementProperty2);
                // xmlElementDefaults.AppendChild(xmlElementProperty3);
                // xmlElementDefaults.AppendChild(xmlElementProperty4);
                // xmlElementDefaults.AppendChild(xmlElementProperty5);
                // xmlElementDefaults.AppendChild(xmlElementProperty6);
                // xmlElementDefaults.AppendChild(xmlElementProperty7);
                // xmlElementDefaults.AppendChild(xmlElementProperty8);

                // xmlElementProperty8.SetAttribute("isHidden", "true");
                // xmlElementProperty8.SetAttribute("isEditable", "false");

                XmlElement xmlElement1 = objXmlDoc.CreateElement("Part");
                xmlElement1.SetAttribute("name", dt.Rows[i][0].ToString());

                XmlElement xmlElement2 = objXmlDoc.CreateElement("Description");
                xmlElement2.InnerText = dt.Rows[i][1].ToString();
                xmlElement1.AppendChild(xmlElement2);
                objNode.AppendChild(xmlElement1);

                XmlElement xmlElementModel = objXmlDoc.CreateElement("Model");
                xmlElementModel.SetAttribute("thickness", "1000.0");
                xmlElementModel.SetAttribute("height", "1000.0");
                XmlElement xmlElementLevel = objXmlDoc.CreateElement("Level");
                xmlElementLevel.InnerText = "INS_Support_NSSS";
                XmlElement xmlElementSymbology = objXmlDoc.CreateElement("Symbology");
                xmlElementSymbology.SetAttribute("color", "BYLEVEL");
                xmlElementSymbology.SetAttribute("style", "BYLEVEL");
                xmlElementSymbology.SetAttribute("weight", "BYLEVEL");
                xmlElementModel.AppendChild(xmlElementLevel);
                xmlElementModel.AppendChild(xmlElementSymbology);
                xmlElement1.AppendChild(xmlElementModel);
                objNode.AppendChild(xmlElement1);
                Console.WriteLine(dt.Rows[i][0].ToString() + "," + dt.Rows[i][1].ToString());

            }

            objXmlDoc.Save(savePath);







            Console.ReadLine();

        }

    }
}
